package org.mybatis.a01;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;
import org.mybatis.entity.User;
import org.mybatis.example.UserMapper;

import java.io.IOException;
import java.io.InputStream;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/12/20 13:05
 */
public class A01 {

  @Test
  public void testSelectOne() throws IOException {
    String resource = "sqlMapConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory =
      new SqlSessionFactoryBuilder().build(inputStream);
    try (SqlSession session = sqlSessionFactory.openSession()) {
//      User user = session.selectOne(
//        "org.mybatis.example.UserMapper.selectOneUser", 1);
//      System.out.println(user);
      UserMapper mapper = session.getMapper(UserMapper.class);
      User user1 = mapper.selectOneUser(1L);
      System.out.println(user1);
    }
  }

  /**
   * 执行查询所有用户的SQL语句必须的步骤
   * 1. 需要获取连接
   * 2. 需要SQL语句
   * 3. 需要将结果集中的数据封装到JavaBean中
   */
}
